package com.color.admin.system.controller;


import com.color.admin.common.core.base.BaseController;
import com.color.admin.common.core.constant.Constant;
import com.color.admin.common.core.page.PageRequest;
import com.color.admin.common.core.result.ResultData;
import com.color.admin.common.logger.annotation.Log;
import com.color.admin.system.entity.BaseEntity;
import com.color.admin.system.entity.SysPost;
import com.color.admin.system.entity.query.PostQueryCriteria;
import com.color.admin.system.servie.PostService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Set;

/**
 * @author HaiQiu
 * @date 2021/12/28
 */
@Tag(name = "post-controller",description = "职位管理接口")
@RestController
@RequestMapping("/system/post")
public class PostController extends BaseController {

    @Autowired
    private PostService postService;


    @Log("职位新增")
    @Operation(summary = "职位新增",description = "职位新增数据接口")
    @PostMapping
    public ResultData save(@RequestBody @Validated SysPost sysPost){
        postService.save(sysPost);
        return decide(Constant.INSERT);
    }

    @Log("职位修改")
    @Operation(summary = "职位修改",description = "职位修改数据接口")
    @PutMapping
    public ResultData update(@RequestBody @Validated(BaseEntity.update.class) SysPost sysPost){
        postService.update(sysPost);
        return decide(Constant.UPDATE);
    }

    @Log("分页模糊查询职位")
    @Operation(summary = "分页查询", description = "分页模糊查询职位")
    @PostMapping("/list")
    public ResultData list(@RequestBody PageRequest<PostQueryCriteria> request) {
        return decide(postService.list(request));
    }

    @Log("职位查询")
    @Operation(summary = "职位查询",description = "职位根据ID查询接口")
    @GetMapping
    public ResultData get(@RequestParam String postId){
        return decide(postService.get(postId));
    }

    @Log("职位删除")
    @Operation(summary = "职位删除",description = "职位根据ID批量删除接口")
    @DeleteMapping
    public ResultData delete(@RequestBody Set<String> postIds){
        postService.delete(postIds);
        return decide(Constant.DELETE);
    }

    @Log("所有职位")
    @Operation(summary = "所有职位",description = "职位查询所有数据接口")
    @GetMapping("/postAll")
    public ResultData postAll(@RequestParam(required = false) String postName){
        return decide(postService.postAll(postName));
    }
}
